package com.bw.seckill_module.bind;

import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bw.seckill_module.entity.GoodsEntity;
import com.bw.seckill_module.seckilllist.SecKillAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.List;

public class SecKillBind {

    @BindingAdapter(value = {"seckill","secclick","secchildclick"})
    public static void bindSeckill(RecyclerView recyclerView, List<GoodsEntity>secKillList,
                                   OnItemClickListener secclick,
                                   OnItemChildClickListener secchildclick){
        SecKillAdapter adapter = (SecKillAdapter) recyclerView.getAdapter();
        if (adapter == null){
            adapter = new SecKillAdapter();
            LinearLayoutManager manager = new LinearLayoutManager(recyclerView.getContext());
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            adapter.setOnItemClickListener(secclick);
            adapter.setOnItemChildClickListener(secchildclick);
            recyclerView.setLayoutManager(manager);
            recyclerView.setAdapter(adapter);
        }else {
            adapter.setNewInstance(secKillList);
        }
    }

}
